let fs = require('fs');


if (!fs.existsSync("file")) fs.mkdirSync("file")


let str = "qwertyuiopasdfghjklzxcvbnm"


let fd = fs.openSync("./file/dome.text","a")


for (let index = 1; index <=1000; index++){
    
  // fs.writeSync(fd,str.slice(Math.floor(Math.random()*(str.length-1))))
  fs.writeSync(fd, str.slice(Math.floor(Math.random() * (str.length - 1))), str.length - 1);

}

fs.closeSync(fd)


var  arr = []
let  read = fs.createReadStream("./file/dome.text")


read.on("data",(chunk)=>{

 let str = chunk.toString()

 for (let index = 0; index < str.length; index++) {
     if(arr[str[index]]==undefined){
        arr[str[index]]=1

     }else{
        arr[str[index]]+=1
     }



 }
 




})

read.on("end",() => {
var max=0
var maxs=''
for (const key in arr ) {
    
   if(max<arr[key]){
     max=arr[key]
     maxs=key

   }

}
console.log("出现次数最多为"+maxs);
})